package com.xiaobai.demo;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j
public class ThreadJoin {
    static int r = 0;
    public static void main(String[] args) {
        try {
            test1();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    public static void test1() throws InterruptedException {
        log.debug("start");
        Thread t1 = new Thread(() -> {
            log.debug("t1 start");
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            log.debug("t1 end");
            r =10;
        },"t1");
        t1.start();
        log.debug("result is {}",r);
        log.debug("end");
        t1.join();
        log.debug("result is join {}",r);
        log.debug("end join");
    }
}
